﻿/*
 * Created by SharpDevelop.
 * User: user
 * Date: 07/09/2011
 * Time: 11:51
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace csharp.rad.lavanderia
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		private String database_name = "lavanderia.sqlite";
		private String sql_file = "../../database/lavanderia.sql";
		public static String name_program= "Lavanderia";
		
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		void CadastroToolStripMenuItemClick(object sender, EventArgs e)
		{
			
		}
		
		void ClientesToolStripMenuItemClick(object sender, EventArgs e)
		{
			entries.frmRegisterCustomer form = new entries.frmRegisterCustomer();
			form.ShowDialog();
		}
		
		void MainFormLoad(object sender, EventArgs e)
		{
			csharp.common.Database.Protocol = csharp.common.Database.SQLITE;
			csharp.common.Database.Name = database_name;
			csharp.common.Database.Password = "evolution";			
			if (!System.IO.File.Exists(database_name)) 
				makeDb(); 
			
			csharp.common.Database.Connect();
			
			if (!csharp.common.Database.IsConnected)
			{
				MessageBox.Show("Banco de dados não conectado!\n"+csharp.common.Database.result.ErrorMessage);
				Application.Exit();
			}

			//TMP
			//common.Database.ExecuteQuery(csharp.common.Util.getContentOfFile("../../database/v_service.sql"));
		}
		
		private void makeDb()
		{
			String sql;
			
			common.Database.createDatabase(false);
			
			common.Database.Connect();
			
			//common.Database.getSqliteConnection().SetPassword(common.Database.Password);
			
			sql = csharp.common.Util.getContentOfFile(sql_file);
			
			common.Database.ExecuteQuery(sql);
		}
		
		void ServiçosToolStripMenuItemClick(object sender, EventArgs e)
		{
			entries.frmRegisterService form = new entries.frmRegisterService(String.Empty);
			
			form.ShowDialog();
		}
		
		void ChequesToolStripMenuItemClick(object sender, EventArgs e)
		{
			frmRegisterCheque form = new frmRegisterCheque();
			form.ShowDialog();
		}
		
		void UsuáriosToolStripMenuItemClick(object sender, EventArgs e)
		{
			frmRegisterUser form = new frmRegisterUser();
			form.ShowDialog();
		}
		
		void ServiçosToolStripMenuItem1Click(object sender, EventArgs e)
		{
			views.frmViewServices form = new csharp.rad.lavanderia.views.frmViewServices();
			form.ShowDialog();
		}
		
		void SairToolStripMenuItemClick(object sender, EventArgs e)
		{
			this.Close();
		}
	}
}

